package com.zrkj.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zrkj.entity.TSysRoleResource;
import com.zrkj.entity.vo.Result;
import com.zrkj.service.ITSysRoleResourceService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : 国良
 * @className : TSysRoleResourceController
 * @package: com.ha.controller
 * @description : 用户组与资源关联表 前端控制器
 * @date :  2021-05-14
 */
@RestController
@RequestMapping(value = "/tSysRoleResource")
@Api(tags = "角色与资源关联表")
public class TSysRoleResourceController {
    private final ITSysRoleResourceService itSysRoleResourceService;

    public TSysRoleResourceController(ITSysRoleResourceService itSysRoleResourceService) {
        this.itSysRoleResourceService = itSysRoleResourceService;
    }

    /**
     * 添加
     *
     * @param tSysRoleResource
     * @return
     */
    @PostMapping("/add")
    public Result<String> add(@RequestBody TSysRoleResource tSysRoleResource) {
        return itSysRoleResourceService.add(tSysRoleResource);
    }

    /**
     * 更新
     *
     * @param tSysRoleResource
     * @return
     */
    @PutMapping(value = "/update")
    public Result<Boolean> update(@RequestBody TSysRoleResource tSysRoleResource) {
        return itSysRoleResourceService.update(tSysRoleResource);
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/delete")
    public Result<Boolean> delete(@RequestParam(value = "ids") String ids) {
        String[] idsArray = ids.split(",");
        List<Long> idList = new ArrayList<>();
        for (String id : idsArray) {
            idList.add(Long.valueOf(id));
        }
        return itSysRoleResourceService.delete(idList);
    }

    /**
     * 查询详情
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/getById/{id}")
    public Result<TSysRoleResource> getById(@PathVariable(value = "id") Long id) {
        return itSysRoleResourceService.getById(id);
    }

    /**
     * 查询列表
     *
     * @param tSysRoleResource
     * @return
     */
    @PostMapping(value = "/queryList")
    public Result<List<TSysRoleResource>> queryList(@RequestBody TSysRoleResource tSysRoleResource) {
        return itSysRoleResourceService.queryList(tSysRoleResource);
    }

    @PostMapping(value = "/queryPageList")
    public Result<IPage<TSysRoleResource>> queryPageList(@RequestBody TSysRoleResource data) {
        return itSysRoleResourceService.queryPageList(data);
    }
}
